package com.example.boke.config.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class interceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        HttpSession session = request.getSession();

        if (session.getAttribute("id") == null)
        {

            response.sendRedirect("/boke/admin/login");
            System.out.println("拦截本次请求：" + request.getRequestURL());
            return false;
        }

        return true;
    }
}
